package cn.lll.vuehouse.controller;

import cn.lll.vuehouse.common.ResponseResult;
import cn.lll.vuehouse.common.ResponseStatus;
import cn.lll.vuehouse.entity.Permission;
import cn.lll.vuehouse.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author:
 * @date: 2023-09-05 9:41
 * @version: 1.0
 * @description:
 */
@RestController
@RequestMapping("permission")
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    // 获取权限列表
    @GetMapping("tree")
    public ResponseResult getAuthTree(){
        return permissionService.getAuthTree();
    }

    // 根据角色id 回显权限 getRolePermissionById
    @GetMapping("getRolePermissionById")
    public ResponseResult getRolePermissionById(Integer id){
        return permissionService.getRolePermissionById(id);
    }

    // 搜索查询 根据title搜索菜单 getPermissionByTitle
    @GetMapping("getPermissionByTitle")
    public ResponseResult getPermissionByTitle(String title){
        return permissionService.getPermissionByTitle(title);
    }


    // 添加菜单  add
    @PostMapping("add")
    public ResponseResult addPermission(@RequestBody Permission permission){
        ResponseResult responseResult = new ResponseResult();
        permissionService.saveOrUpdate(permission);
        responseResult.success(ResponseStatus.SUCCESS);
        return responseResult;
    }

    // 根据id回显菜单信息 getPermissionById
    @GetMapping("getPermissionById")
    public ResponseResult getPermissionById(Integer id){
        return permissionService.getPermissionById(id);
    }

    // 根据id删除菜单 deletePermissionById
    @DeleteMapping("deletePermissionById")
    public ResponseResult deletePermissionById(Integer id){
        return permissionService.deletePermissionById(id);
    }



}
